//
//  LGForumViewController.m
//  ligenyun
//
//  Created by apple on 2018/3/23.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGForumViewController.h"
#import "LGForumHomeTableViewCell.h"
#import "LGForumHelpCenterViewController.h"
#import "LGForumDetailViewController.h"
#import "LGMInePersonalCenterViewController.h"
@interface LGForumViewController ()
@property(nonatomic, strong) UISegmentedControl     *segement;
@end

@implementation LGForumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"礼根论坛";
    [self configSubView];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"个人主页_未选中"]];
    // Do any additional setup after loading the view.
}

#pragma mark --SubView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
    header.backgroundColor = [UIColor clearColor];
    __weak typeof(self) weakSelf = self;
    NSArray * array = @[@"热门板块:",@"帮助中心",@"文化交流",@"全部板块"];
    CGFloat buttonWith = UIScreenWidth / 4;
    for (NSInteger i = 0; i < array.count; i ++ ) {
        NSString * title = array[i];
        STButton * menuButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, buttonWith, 44)
                                                          title:title
                                                     titleColor:SecendTextColor
                                                      titleFont:14
                                                   cornerRadius:0
                                                backgroundColor:nil
                                                backgroundImage:nil
                                                          image:nil];
        [menuButton setClicAction:^(UIButton *sender) {
            [weakSelf onSelctedTitleButton:sender];
        }];
        menuButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [header addSubview:menuButton];
        menuButton.left = i * buttonWith;
    }
    
    CGFloat segementWith = (UIScreenWidth - 30)/3;
    self.segement = [[UISegmentedControl alloc] initWithItems:@[@"全部",@"最新",@"最热"]];
    self.segement.frame = CGRectMake(15, 44, segementWith * 3, 30);
    self.segement.tintColor = FlatGray;
    self.segement.selectedSegmentIndex = 0;
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateSelected];
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
    [self.segement addTarget:self action:@selector(onSelctedSegement:) forControlEvents:UIControlEventValueChanged];
    [header addSubview:self.segement];
    header.height = self.segement.bottom + 30;
    self.tableView.tableHeaderView = header;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGForumHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGForumHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGForumHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.navigationController pushViewController:[LGForumDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)onSelctedTitleButton:(UIButton*)sender{
    if ([sender.currentTitle isEqualToString:@"帮助中心"]) {
        [self.navigationController pushViewController:[LGForumHelpCenterViewController new] animated:YES];
    }
}
- (void)onSelctedSegement:(UISegmentedControl*)seg{
    
}
- (void)st_rightBarAction:(id)sender{
    [self.navigationController pushViewController:[LGMInePersonalCenterViewController new] animated:YES];
}
@end
